/*
 * Algorithm
 *
 * SJSU CS 149 Spring 2009 Project
 *
 * Copyright 2009 Timmy Yee
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * The Algorithm enum class contains different scheduling algorithm
 * constants that can be used within the simulator to identify the correct
 * algorithm to use.
 *
 * @author Timmy Yee
 */
public enum Algorithm
{
    PREEMPT,
    NON_PREEMPT,
    ROUND_ROBIN,
    RANDOM,
    CLOCK;

    /**
     * Parses the name of the given process or memory management algorithm.
     *
     * @param algorithm The given management algorithm.
     * @return          The name of the given management algorithm.
     * @throws IllegalArgumentException If given algorithm is invalid.
     */
    public static String valueOf(Algorithm algorithm)
    {
        if (algorithm == Algorithm.PREEMPT)
            return "Preemptive Priority";
        else if (algorithm == Algorithm.NON_PREEMPT)
            return "Non-preemptive Priority";
        else if (algorithm == Algorithm.ROUND_ROBIN)
            return "Round Robin";
        else if (algorithm == Algorithm.RANDOM)
            return "Random Replacement";
        else if (algorithm == Algorithm.CLOCK)
            return "Clock LRU (Second-chance)";
        else
            throw new IllegalArgumentException("invalid algorithm");
    }
}

